//package xuegao.study.mall.gateway.runner;
//
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
//import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.boot.ApplicationArguments;
//import org.springframework.boot.ApplicationRunner;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 这种方式可以手动加载规则,存储在内存。但是会在配置中心的规则刷新时被覆盖掉。生产环境不建议使用它
// */
//@Component
//public class FlowRuleRunner implements ApplicationRunner {
//
//    private Logger log = LoggerFactory.getLogger(FlowRuleRunner.class);
//
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        try {
//            List<FlowRule> rules = FlowRuleManager.getRules();
//            if (rules == null) {
//                rules = new ArrayList<>();
//            }
//            FlowRule flowRule = new FlowRule("/refreshRoutes");
//            flowRule.setCount(5);
//            flowRule.setClusterMode(false);
//            flowRule.setControlBehavior(0);
//            flowRule.setLimitApp("default");
//            rules.add(flowRule);
//            log.info("FlowRuleRunner loadRules reules:{}  ",rules);
//            FlowRuleManager.loadRules(rules);
//        } catch (Exception e) {
//            log.error("FlowRuleRunner 加载异常 :{}",e.getMessage());
//        }
//    }
//}
